﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crosland.Automotriz.Core;

namespace Crosland.Automotriz.Data.Dao.Linq
{
    public class clsT_Log_Material_ImagenDAO
    {

        private AutomotrizEntities ContextoDeObjs = new AutomotrizEntities();

        public List<T_LOG_MATERIAL_IMAGEN> ListaPorIdMaterial(int intIdMaterial) {

            List<T_LOG_MATERIAL_IMAGEN> lista = new List<T_LOG_MATERIAL_IMAGEN>();

            var q = from m in ContextoDeObjs.T_LOG_MATERIAL_IMAGEN
                    where m.ID_MATERIAL == intIdMaterial
                    select m;



            lista = q.ToList();

            return lista;
        }





        public bool Insertar(T_LOG_MATERIAL_IMAGEN Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("T_LOG_MATERIAL_IMAGEN", Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        public int UltimoNumero()
        {
            var max = 0;

            try
            {
                max = ContextoDeObjs.T_LOG_MATERIAL_IMAGEN.Select(x => x.ID_LOG_MATERIAL_IMAGEN).Max();

            }
            catch (Exception)
            {
                max = 0;
               
            }

            return max;
        }



        public bool EliminaPorIdMaterial(int idMaterial) {

            try
            {
                ContextoDeObjs.ExecuteStoreCommand("DELETE FROM T_LOG_MATERIAL_IMAGEN WHERE ID_MATERIAL="+idMaterial);
            }
            catch (Exception ex)
            {
                
                throw ex;
            }

            return true;
        }

    }
}
